package com.blog.Utils;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Map;

/**
 * @author 任浩
 * @version 1.0
 *
 *  okHttp调用工具类。
 */

@Slf4j
public class OkHttpUtil {
    private static final OkHttpInstance okHttpInstance = new OkHttpInstance();

    /**
     * 无参数，无请求头get请求
     * @return
     */
    public static String get(String url){
        String res = okHttpInstance.get(url);

        return res;
    }

    /**
     * 有参数，无请求头get请求
     * @return
     */
    public static String get(Map<String,Object> params,String url){
        String res = okHttpInstance.get(params,url);

        return res;
    }

    /**
     * 有参数，有请求头get请求
     * @return
     */
    public static String get(Map<String,Object> params,Map<String,String> headers, String url){
        String res = okHttpInstance.get(params,headers,url);

        return res;
    }

    /**
     * post请求
     * @return
     */
    public static String post(String url,String json,Map<String, String> headers){
        log.info("post请求的地址为: {}",url);
        log.info("post请求参数为: {}",json);
        String res = okHttpInstance.post(url,json,headers);
        return res;
    }

}
